package com.example.demo;


import catcode.CatCodeUtil;
import com.alibaba.fastjson.JSONObject;
import com.example.demo.Switch.PublicApiController;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class test extends Thread{
    static int i=0;
    static String name=null;
    static Object o=new Object();


    public static void main(String[] args) {

        // 获取猫猫码工具
        CatCodeUtil util = CatCodeUtil.INSTANCE;

        // 构建at
        String at = util.toCat("at", "code=123456");

        // 构建image, 第二个参数为true代表参数值需要进行转义
        String image = util.toCat("image", true, "url=http://image.jpg");

        System.out.println(image);

        /*test test=new test();
        test test2=new test();
        test.start();
        test2.start();*/
        /*for (int j = 0; j < 10; j++) {
            try {
                sleep(1000);
                System.out.println(++i);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }*/

       /* getLicense("123");*/

    }


    public static JSONObject getLicense(String authCode) {

        RestTemplate restTemplate=new RestTemplate();
        MultiValueMap<String,String> params=new LinkedMultiValueMap<>();

        params.add("access_token","123");
        params.add("auth_code",authCode);

        String url="123.123.123:89/license/alipay/get_license";
        JSONObject jsonObject=restTemplate.postForObject(url,params,JSONObject.class);

        return jsonObject;
    }


    public void run() {
        /*while (true)
        {
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (o)
            {
                System.out.println("线程："+name+"运行"+i++);
                if (i>=10)
                {
                    break;
                }
            }
        }*/
        for (int j = 0; j < 10; j++) {
            System.out.println(j);
        }
    }

    public static void hashCode(String userid) {
        Date date=new Date();
        SimpleDateFormat time=new SimpleDateFormat("yy-MM-dd");
        String all=time.format(date);
        System.out.println(all);
        StringBuilder zz= new StringBuilder();
        for (int i=0;i<8;i=i+3)
        {
            zz.append(all, i, i + 2);
        }
        System.out.println(userid.substring(0,6));
        System.out.println(zz);
        int id= Integer.parseInt(userid.substring(0,6))+Integer.parseInt(zz.toString());

        System.out.println(id);
        //获取最终随机种子 生成0-100的随机数
        Random R=new Random(id);
        id=R.nextInt(101);
        String cat="[CAT:at,code="+userid+"]您的今日人品是:"+id;
        System.out.println(cat);
    }
    /*System.out.println(Rand("1181247962"));
        System.out.println(Rand("783743165"));*/
    /*public static int Rand(String userid)
    {
        String zz="211114";
        int qwe= Integer.parseInt(userid.substring(0,3)+zz);
        Random r=new Random(qwe);
        int math=r.nextInt(1000);
        Random R=new Random(math);
        math=R.nextInt(101);
        return math;

    }*/


}
